#ifndef _OI_PLSCANNERCORE_DYNAMICSPLINECHART_H_
#define _OI_PLSCANNERCORE_DYNAMICSPLINECHART_H_

#include "PLScannerCore/OiPLScannerCore.hpp"
#include <QtCharts/QChart>

//#define XAXIS_CHARTS_RANGE 60*60

namespace Oi
{
    namespace PLScannerCore
    {
        class OiCheckedLegend : public QCheckBox
        {
            Q_OBJECT

        public:
            OiCheckedLegend(QWidget* parent = nullptr);
            void setColor(QColor bg);
        };


        class OI_PLSCANNER_CORE_API DynamicSplineChart : public QtCharts::QChart
        {
            Q_OBJECT

        public:
            enum FitnessMode
            {
                FitToData,
                FitToLimite,
            };

        public:
            DynamicSplineChart(QStringList splines, QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags());
            virtual ~DynamicSplineChart();

        public:
            QMap<QString, OiCheckedLegend*> legends() const;
            QStringList splines() const;

        public:
            bool isRunning();
            void run(bool);

            void addValue(QString s, qreal dt, qreal value);
            void addValues(qreal dt, QMap<QString, qreal> values);

            void setValue(QString s, const QList<QPointF>&);
            void setValues(const QMap<QString, QList<QPointF>>&);

            void setLimit( const double upper, const double lower);

            void onFlash();

            void updatePlotAreaBackground();

            void setFlashFitMode(FitnessMode mode);

            void yAxisFittness(FitnessMode mode = FitToData);

            void setMinYRange(const double upper, const double lower);

            void setYFormat(QString);

            void setXRange(int);

            int xRange() const;

        signals:
            void flash();


        public slots:
            void onLegendChecked();

        private:
            OI_DISABLE_COPY(DynamicSplineChart);
            OI_DECLARE_IMPL(DynamicSplineChart);
        };

    }
}


#endif
